package com.hopu.blb_erp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.ProductionProcess;
import com.hopu.blb_erp.mapper.Order2Mapper;
import com.hopu.blb_erp.mapper.ProductionProcessMapper;
import com.hopu.blb_erp.service.ProductionProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductionProcessServiceImpl extends ServiceImpl<ProductionProcessMapper,ProductionProcess> implements ProductionProcessService{
    @Autowired
    private ProductionProcessMapper productionProcessMapper;
    @Autowired
    private Order2Mapper order2Mapper;
    @Override
    public PageEntity<ProductionProcess> findAllPage(int current, int PAGE_SIZE, int orderId) {
        int count = order2Mapper.selectAllCount();
        int pageCount =  count % PAGE_SIZE==0?count/PAGE_SIZE:count/PAGE_SIZE+1;
        List<ProductionProcess> productionProcessList = productionProcessMapper.selectAllLimit((current-1)*PAGE_SIZE,PAGE_SIZE,orderId);
        PageEntity<ProductionProcess> page = new PageEntity<>();
        page.setCurrent(current);
        page.setData(productionProcessList);
        page.setPageCount(pageCount);
        page.setCount(count);
        return page;
    }
}
